new Vue({
	el: '#app',
	data: {
		key_name: '',
		searchList: [],
		isShow: false,
		page: '1',
		t: []
	},
	mounted: function() {
		this.init();
	},
	methods: {
		init: function() {
			var self = this;
			//self.getList();
			apiready = function() {
				var fid = api.pageParam;
				self.key_name = fid.key_name;
				//loading加载
				self.isS();
			}
		},
		isS: function() {
			var self = this;
			var UILoading = api.require('UILoading');
			if(self.isShow) {
				console.log(self.loadingId);
				UILoading.closeFlower({
					id: self.loadingId
				});
			} else {
				UILoading.flower({
					center: {
						x: api.winWidth / 2.0,
						y: api.winHeight / 2.0
					},
					size: 30,
					fixed: true
				}, function(ret) {
					console.log(JSON.stringify(ret));
					self.loadingId = ret.id;
				});
				self.getList();
			}
		},
		//获得文章列表
		getList: function() {
			var self = this;
			var data = {
				keyword: self.key_name,
				page: self.page
			}
			$.post(base + config.sns_question_find, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					self.t = msg.data;
					for(var i = 0; i < self.t.length; i++) {
						self.searchList.push(self.t[i]);
					};
					self.pageCount = msg.page_count;
					self.isShow = true;
					self.isS();
				} else {
					self.isShow = true;
					self.isS();
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		},
		//跳转到文章详情列表
		jumpDetails: function(id) {
			api.openWin({
				name: 'question-details',
				url: 'questionDetails.html',
				vScrollBarEnabled: false,
				pageParam: {
					qid: id
				}
			});
		},
		del: function() {
			var self = this;
			self.key_name = "";
			self.searchList = [];
		},
		//
		search: function() {
			var self = this;
			if(self.key_name) {
				self.searchList = [];
				self.isShow = false;
				self.isS();
			} else {
				api.toast({
					msg: '搜索内容不能为空',
					duration: 2000,
					location: 'middle'
				});
			}

		},
		close:function(){
			api.closeWin();
		}
	}
})